package mianyang.zhangsan.com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import mianyang.zhangsan.com.mapper.SelectedCourseMapper;
import mianyang.zhangsan.com.pojo.SelectedCourse;
import mianyang.zhangsan.com.service.SelectedCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("selectedCourseService")
public class SelectedCourseServiceImpl implements SelectedCourseService {
    @Autowired
    private SelectedCourseMapper selectedCourseMapper;

    @Override
    public void addSelected(SelectedCourse selectedCourse) {
        selectedCourseMapper.insert(selectedCourse);
    }

    @Override
    public Page<SelectedCourse> queryByPage(int page, int size, int studentId, int courseId) {
        QueryWrapper<SelectedCourse> wrapper = null;
        if (studentId != 0){
            wrapper.eq("student_id", studentId);
        }
        if (courseId != 0){
            wrapper.eq("course_id", courseId);
        }
        return selectedCourseMapper.selectPage(new Page<>(page, size), wrapper);
    }

    @Override
    public void deleteSelected(int id) {
        QueryWrapper<SelectedCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        selectedCourseMapper.delete(wrapper);
    }
}
